<template>
  <div style="border-bottom: 1px solid #dfdfdf;font-size: 14px; width: 100%">
    <div style="display: flex;height: 40px;padding: 0 200px;background-color: #19b4ea;width: 100%">
      <div class="top-title" style="padding-right: 20px;border-right: 1px solid rgb(230 230 230);line-height: 40px;color: #ffffff;" @click="toRouter('index')">首页</div>
      <div class="top-title" style="padding-right: 20px;border-right: 1px solid rgb(230 230 230);line-height: 40px;color: #ffffff;margin-left: 20px;" @click="toRouter('classify')">商品分类</div>
      <div class="top-title" style="padding-right: 20px;border-right: 1px solid rgb(230 230 230);line-height: 40px;color: #ffffff;margin-left: 20px;" @click="toRouter('car')">购物车</div>
      <div class="top-title" style="line-height: 40px;color: #ffffff;margin-left: 20px;" @click="toRouter('order/list')">我的订单</div>
      <div style="flex: 1;display: flex;">
        <div style="flex: 1;"></div>
        <div style="width: 170px;display: flex;">
<!--          <el-image  v-if="isLogin" :src="headUrl + $store.state.user.avatar" style="cursor: pointer;height: 30px;margin-top: 5px;margin-right: 10px;"></el-image>-->
          <img  v-if="isLogin" :src="avatar" style="cursor: pointer;height: 30px;margin-top: 5px;margin-right: 10px; border-radius: 50px;">
          <el-button type="text" v-if="isLogin" style="color: #ffffff;" class="top-title">您好：{{name}}</el-button>
          <div style="margin-top: 10px" v-if="isLogin">
            <el-dropdown>
              <i class="el-icon-arrow-down el-icon--right"></i>
              <el-dropdown-menu slot="dropdown" style="margin-top: 20px;" >
                <el-dropdown-item divided @click.native="Lookme">
                  <span >个人中心</span>
                </el-dropdown-item>
                <el-dropdown-item divided @click.native="logout">
                  <span>退出登录</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <el-button v-if="!isLogin" type="text" @click="jump" style="color: #FFFFFF;" class="top-title">请 登 录 </el-button>
<!--          <el-button type="text" @click="jump1" style="color: #FFFFFF;margin-right: 10px;" class="top-title">注册</el-button>-->

          <div style="background-color: rgb(25,180,234);display: flex;width: 100px;padding: 0 10px;" class="top-title">
            <img src="@/assets/img/shop_car.png" style="width: 20px;height: 20px;margin-top: 10px;margin-left: 10px;margin-right: 5px;">
            <el-button type="text" style="color: #ffffff;" class="top-title">购物车</el-button>
          </div>

        </div>

      </div>
    </div>


      <profile ref="profile"/>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {headUrl} from "../../../utils/common";
import Profile from "../../user/profile";

export default {

  name:"indexTop",
  components: {Profile},
  data() {
    return {
      open:false,
      input:'',
      headUrl
    };
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'device'
    ]),
  },
  props:['name','isLogin'],

  methods: {
    Lookme(){
      this.$refs.profile.handleOpen()
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/index';
          this.isLogin = false
        })
      }).catch(() => {});
    },
    jump () {
      this.$router.push('/login')
    },

    jump1 () {
      this.$router.push('/register')
    },

    toRouter (index) {
      this.$router.push('/'+index)
    },
    getUrl(url) {
      return headUrl + $store.state.user.avatar + url
    }

  }
};
</script>

<style>
.top-title:hover{
  cursor: pointer;
  color: #e5e5e5!important;
}
.title{
  font-weight: bold;
  font-size: 18px;
  margin-top: -20px;
}
.title:hover{
  color: #c250c6!important;
}

.title1{
  font-weight: bold;
  font-size: 28px;
  color: #808080;
}

</style>
